﻿function RoundNumber(number, decimal) {
    var multiplier = Math.pow(10, decimal);
    if (number > 0) {
        return Math.round(number * multiplier) / multiplier;
    } else {
        return 0;
    }
}

function BindSelectFields(field) {
    $('#' + field).change(function() {
        $.ajax({
            type: 'POST',
            url: 'forms/Default.aspx/FilterResults',
            data: '{"selectedClass":"' + $('#class').val() + '", "selectedRace":"' + $('#race').val() + '", "selectedGender":"' + $('#gender').val() + '"}',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function(msg) {
                $('#totalCharacters').html(msg.d.TotalCharacters);
                $('#averageCharacterLevel').html(msg.d.AverageCharacterLevel);
                $('#charactersAtMaxLevel').html(msg.d.CharactersAtMaxLevel + ' - ' + RoundNumber((msg.d.CharactersAtMaxLevel / msg.d.TotalCharacters) * 100, 2) + '%');
                $('#maxAchievementPoints').html(msg.d.MaxAchievementPoints);
                $('#averageAchievementPoints').html(msg.d.AverageAchievementPoints);
            }
        });
    });
}